수업 7에 오신 것을 환영합니다. 여기서 우리는 전이 학습. 이 기술은 이미 거대하고 일반적인 데이터셋(예: ImageNet)에서 훈련된 딥러닝 모델을 재사용하여 새로운 특정 과제(예: 저희의 음식 시각화 도전 과제)에 적응시키는 것입니다. 레이블이 붙은 데이터셋이 제한적인 경우에 특히, 최첨단 성능을 효율적으로 달성하는 데 필수적입니다.
1. 사전 훈련된 가중치의 힘
딥 신경망은 계층적으로 특징을 학습합니다. 낮은 레이어는 기본 개념(선, 모서리, 질감)을 배우고, 더 깊은 레이어는 이를 복합 개념(눈, 바퀴, 특정 물체)으로 조합합니다. 핵심 통찰은 초기에 학습된 기본 특징들이 대부분의 시각적 영역에서 보편적으로 적용 가능 다양한 시각적 영역에서 보편적으로 적용될 수 있다는 점입니다.
전이 학습 구성 요소
- 원본 작업: 1,400만 장의 이미지와 1,000개 범주에서 훈련(예: ImageNet).
- 목표 작업: 더 작은 데이터셋(예: 저희의 특정 음식 시각화 클래스)을 분류하도록 가중치를 적응시키기.
- 활용된 구성 요소: 네트워크의 대부분의 파라미터—특징 추출 레이어—는 직접 재사용됩니다.
효율성 증가
전이 학습은 두 가지 주요 자원 장벽을 크게 줄입니다: 계산 비용 (일주일 이상 모델 전체를 훈련하지 않아도 됩니다) 및 데이터 요구량 (수백 개의 훈련 예제로도 높은 정확도를 달성할 수 있습니다).
TERMINALbash — pytorch-env
> Ready. Click "Run" to execute.
>
TENSOR INSPECTOR Live
Run code to inspect active tensors
Question 1
What is the primary advantage of using a model pre-trained on ImageNet for a new vision task?
Question 2
In a Transfer Learning workflow, which part of the neural network is typically frozen?
Question 3
When replacing the classifier head in PyTorch, what parameter must you first determine from the frozen base?
Challenge: Adapting the Classifier Head
Designing a new classifier for FoodVision.
You load a ResNet model pre-trained on ImageNet. Its last feature layer outputs a vector of size 512. Your 'FoodVision' project has 7 distinct food classes.
Step 1
What is the required Input Feature size for the new, trainable Linear Layer?
Solution:
The Input Feature size must match the output of the frozen base layer.
Size: 512.
The Input Feature size must match the output of the frozen base layer.
Size: 512.
Step 2
What is the PyTorch code snippet to create this new classification layer (assuming the output is named `new_layer`)?
Solution:
The output size of 512 is the input, and the class count 7 is the output.
Code:
The output size of 512 is the input, and the class count 7 is the output.
Code:
new_layer = torch.nn.Linear(512, 7)Step 3
What is the required Output Feature size for the new Linear Layer?
Solution:
The Output Feature size must match the number of target classes.
Size: 7.
The Output Feature size must match the number of target classes.
Size: 7.